#include "runningline.h"
#include <QPainter>

RunningLine::RunningLine(QQuickItem *parent) :
    QQuickPaintedItem(parent)
{
    setFlag(QQuickItem::ItemHasContents, true);

    mTextPix = QPixmap(600, 120);
    mTextPix.fill(Qt::white);
    QPainter p(&mTextPix);
    p.setPen(Qt::red);
    QFont font("Ubuntu");
    font.setPointSize(48);
    p.setFont(font);
    p.drawText(0, 120, "1234567890qwertyuio");

    mTimer = new QTimer(this);
    mTimer->setInterval(50);
    mTimer->setSingleShot(false);
    connect(mTimer, SIGNAL(timeout()),
            this, SLOT(timeout()));
    mTextX = 0;
    mTimer->start();
}

void RunningLine::paint(QPainter *p)
{
    QRect r(0, 0, 200, 200);

p->setRenderHint(QPainter::Antialiasing);
    p->drawPixmap(mTextX, 0, mTextPix);

}

void RunningLine::timeout()
{
    mTextX -= 5;
    if (mTextX <= -600)
        mTextX = 0;
    update();
}
